package com.zc.timedown.utils;

/**
 * ClassName:WeChatUserLifeCalculator
 * Description:
 * DateTime: 2025/10/21 8:25
 * Author: zc
 * Version: 1.0
 */

import com.zc.timedown.vo.LifeSpanStatisticsVo;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

/**
 * 微信用户预期寿命计算器
 */
public class WeChatUserLifeCalculator {

    /**
     * 计算用户预期寿命相关信息
     * @param birthday 用户生日
     * @param estimatedLifespan 预估寿命(年)
     * @return 预期寿命统计信息
     */
    public LifeSpanStatisticsVo calculateLifeSpanStatistics(LocalDate birthday, int estimatedLifespan) {
        // 计算预计死亡日期
        LocalDate estimatedDeathDate = birthday.plusYears(estimatedLifespan);

        // 获取当前日期
        LocalDate currentDate = LocalDate.now();

        // 计算已过天数
        long daysLived = ChronoUnit.DAYS.between(birthday, currentDate);

        // 计算总预期天数
        long totalExpectedDays = ChronoUnit.DAYS.between(birthday, estimatedDeathDate);

        // 计算剩余天数
        long daysRemaining = ChronoUnit.DAYS.between(currentDate, estimatedDeathDate);

        // 计算已过天数百分比
        double percentageLived = (daysLived * 100.0) / totalExpectedDays;

        return new LifeSpanStatisticsVo(daysLived, daysRemaining, percentageLived);
    }
}
